﻿#include "mainwindow.h"

#include <QApplication>
#include <QTextCodec>
#include <QSplashScreen>
#include <QDebug>
#include <QMovie>
#include <QDateTime>
#include "Customsplashscreen.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    const QPixmap pixmap = QPixmap(658,494);//gif动画的尺寸大小
    CustomSplashScreen splash;//利用QPixmap对象创建一个QSplashScreen对象
    splash.setPixmap(pixmap);
    QLabel label(&splash);
    QTime randtime;
    randtime = QTime::currentTime();
    qsrand(randtime.msec()+randtime.second()*1000); //以当前时间ms为随机种子

    int n = qrand() % 5;    //产生100以内的随机整数

    //设置label大小和位置
    QMovie mv(":/image/image/loading.gif");
    label.setMovie(&mv);
    mv.setCacheMode(QMovie::CacheAll);
    mv.setSpeed(160);
    qDebug()<<mv.speed()<<mv.frameCount()<<endl;
    mv.start();
    //显示此启动图片
    splash.show();
    splash.setCursor(Qt::BlankCursor);
    QDateTime time = QDateTime::currentDateTime();
    QDateTime currentTime = QDateTime::currentDateTime(); //记录当前时间
    while (time.secsTo(currentTime) <= n) // 5为需要延时的秒数
    {
      currentTime = QDateTime::currentDateTime();
      a.processEvents();
    };
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
    QTextCodec *codec = QTextCodec::codecForName("GBK");
#else
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
#endif
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);
#else
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);
#endif
    MainWindow w;
    w.show();
    splash.finish(&w); //在主体对象初始化完成后结束启动动画
    return a.exec();
}
